package me.shurufa.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.modelmsg.SendAuth;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;

import me.shurufa.R;


/**
 * Created by kHRYSTAL on 15/7/23.
 */
public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Global.mWxApi.handleIntent(getIntent(), this);
  }

  @Override
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    // Global.mWxApi.handleIntent(intent, this);
  }


  @Override
  public void onReq(BaseReq baseReq) {

  }

  @Override
  public void onResp(BaseResp baseResp) {
    if (baseResp instanceof SendAuth.Resp) {
      // LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
      // Intent intent = new Intent(Constants.ACTION_WECHAT_LOGIN);
      // intent.putExtra("result", baseResp.errCode == BaseResp.ErrCode.ERR_OK);
      // intent.putExtra("code", ((SendAuth.Resp) baseResp).code);
      // lbm.sendBroadcast(intent);
      // finish();
    } else {
      int result = 0;
      switch (baseResp.errCode) {
        case BaseResp.ErrCode.ERR_OK:
          result = R.string.errcode_success;
          break;
        case BaseResp.ErrCode.ERR_USER_CANCEL:
          result = R.string.errcode_cancel;
          break;
        case BaseResp.ErrCode.ERR_AUTH_DENIED:
          result = R.string.errcode_deny;
          break;
        default:
          result = R.string.errcode_unknown;
          break;
      }

      Toast.makeText(this, getString(result), Toast.LENGTH_LONG).show();
      finish();
    }
  }
}
